/*********************************************************************************************************************
 * COPYRIGHT NOTICE
 * Copyright (c) 2018,逐飞科技
 * All rights reserved.
 * 技术讨论QQ群：	一群：179029047(已满)
 *					二群：244861897(已满)
 *					三群：824575535
 *
 * 以下所有内容版权均属逐飞科技所有，未经允许不得用于商业用途，
 * 欢迎各位使用并传播本程序，修改内容时必须保留逐飞科技的版权声明。
 *
 * @file			zf_ctimer.h
 * @company			成都逐飞科技有限公司
 * @author			逐飞科技(QQ3184284598)
 * @version			查看doc内version文件 版本说明
 * @Software		IAR 8.3 or MDK 5.24
 * @Taobao			https://seekfree.taobao.com/
 * @date			2020-03-25
 * @note			本文件作为 LPC55S 系列芯片开源库外设文件
					提供 CTIMER 外设驱动
 ********************************************************************************************************************/

#ifndef _ZF_CTIMER_H_
#define _ZF_CTIMER_H_

#ifdef RT_THREAD												// 如果启用了 RT-Thread OS
#include <rthw.h>
#include <rtthread.h>
#endif

#include "core_board_config.h"
#include "fsl_common.h"
#include "fsl_ctimer.h"

typedef enum
{
	CTM_0 = 0x00U,					// 选项 0 对应CTM0
	CTM_1 = 0x01U,					// 选项 1 对应CTM1
	CTM_2 = 0x02U,					// 选项 2 对应CTM2
	CTM_3 = 0x03U,					// 选项 3 对应CTM3
	CTM_4 = 0x04U,					// 选项 4 对应CTM4
}ctimer_index_list;

typedef enum
{
	CTM_CH_0 = 0x00U,					// 选项 0 对应 CH0
	CTM_CH_1 = 0x01U,					// 选项 1 对应 CH1
	CTM_CH_2 = 0x02U,					// 选项 2 对应 CH2
	CTM_CH_3 = 0x03U,					// 选项 3 对应 CH3
}ctimer_channel_index_list;

typedef enum
{
	CTIMER_PARAM_TIMER_MODE,
	CTIMER_PARAM_CAPIN_SELECT,
	CTIMER_PARAM_PRESCALE_SET,
}ctimer_param_list;

typedef enum
{
	CTIMER_TIMER_MODE_TIMER_COUNT,
	CTIMER_TIMER_MODE_CAP_RISING_EDGE,
	CTIMER_TIMER_MODE_CAP_FALLING_EDGE,
	CTIMER_TIMER_MODE_CAP_BOTH_EDGE,
}ctimer_timer_mode_list;

typedef enum
{
	CT_INP00_P0_01,
	CT_INP00_P0_13,
	CT_INP01_P0_02,
	CT_INP01_P0_14,
	CT_INP02_P1_00,
	CT_INP02_P1_28,
	CT_INP03_P1_01,
	CT_INP03_P1_26,
	CT_INP04_P1_09,
	CT_INP04_P0_16,
	CT_INP05_P1_11,
	CT_INP06_P1_13,
	CT_INP07_P1_15,
	CT_INP08_P0_24,
	CT_INP09_P0_25,
	CT_INP10_P0_10,
	CT_INP11_P0_28,
	CT_INP12_P0_04,
	CT_INP13_P0_06,
	CT_INP14_P1_20,
	CT_INP14_P0_26,
	CT_INP15_P0_20,
	CT_INP15_P0_22,
	CT_INP16_P0_15,
}ctimer_capture_pin_list;

extern CTIMER_Type *ctimer_list[5];
extern clock_attach_id_t  ctimer_clock_list[5];

void zf_ctimer_get_default_config (ctimer_config_t *config);
void zf_ctimer_timer_init (ctimer_index_list index, ctimer_channel_index_list cycleChannel, uint32_t pwmfreq_hz);
void zf_ctimer_capture_init (ctimer_index_list index, ctimer_timer_mode_list mode, ctimer_capture_pin_list pin);
void zf_ctimer_set_freq (ctimer_index_list index, ctimer_channel_index_list cycleChannel, uint32_t pwmfreq_hz);

void zf_ctimer_intterupt_enable (ctimer_index_list index, void handler(void));
void zf_ctimer_intterupt_disable (ctimer_index_list index);
void zf_ctiemr_start (ctimer_index_list index);
void zf_ctiemr_stop (ctimer_index_list index);
void zf_ctimer_reset_count (ctimer_index_list index);
uint32_t zf_ctimer_get_count (ctimer_index_list index);

void zf_ctimer_pwm_setup (ctimer_index_list index, ctimer_channel_index_list selectChannel);
void zf_ctimer_pwm_update_duty (ctimer_index_list index, ctimer_channel_index_list selectChannel, uint8_t dutyCyclePercent);

#endif
